"""example of how to cluster a graph based on edges curvatures"""
import pickle

import networkx as nx
import matplotlib.pyplot as plt

from geometric_clustering import load_curvature
from geometric_clustering.plotting import plot_communities
from pygenstability.plotting import plot_scan

if __name__ == "__main__":

    graph = nx.read_gpickle("graph_powergrid.gpickle")
    graph = nx.convert_node_labels_to_integers(graph)

    times, kappas = load_curvature(filename="curvature.pkl")
    times = times[:-5]
    kappas = kappas[:-5]

    cluster_results = pickle.load(open("cluster_results.pkl", "rb"))

    plt.figure(figsize=(5, 3))
    plot_scan(cluster_results, figure_name="clustering_scan.pdf", use_plotly=False)

    plot_scan(
        cluster_results,
        figure_name="clustering_scan.pdf",
        use_plotly=True,
        live=False,
        plotly_filename="clustering_scan.html",
    )
    plot_communities(graph, kappas, cluster_results, ext=".pdf", folder="communities")
